home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / qmgr / qmgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  11.4 KB  |  466 lines

  1. /* qmgr.c: Queue manager main routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/qmgr/RCS/qmgr.c,v 6.0 1991/12/18 20:27:38 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/qmgr/RCS/qmgr.c,v 6.0 1991/12/18 20:27:38 jpo Rel $
  9.  *
  10.  * $Log: qmgr.c,v $
  11.  * Revision 6.0  1991/12/18  20:27:38  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include <sys/signal.h>
  20. #include "ryresponder.h"                /* for generic idempotent responders */
  21. #include "qmgr.h"                   /* operation definitions */
  22. #include "types.h"
  23.  
  24. static char *myservice = "pp qmgr";
  25. extern char *quedfldir;
  26. static SFD debug_on (), debug_off (), shutdown (), spurious ();
  27. int ureject ();
  28.  
  29. /* OPERATIONS */
  30. static int
  31.     op_newmessage (), op_readmsginfo (),
  32.     op_channelbegin (), op_channelread (),
  33.     op_channelcontrol (), op_mtaread (), op_mtacontrol (),
  34.     op_messagecontrol (), op_qmgrcontrol (),
  35.     op_readchannelmtamessage (), op_qmgrstatus ();
  36.  
  37.  
  38. static struct server_dispatch dispatches[] = {
  39.     "newmessage",       operation_Qmgr_newmessage,      op_newmessage,
  40.     "readmsginfo",      operation_Qmgr_readmsginfo,     op_readmsginfo,
  41.     "channelbegin",     operation_Qmgr_channelbegin,    op_channelbegin,
  42.     "channelread",      operation_Qmgr_channelread,     op_channelread,
  43.     "channelcontrol",   operation_Qmgr_channelcontrol,  op_channelcontrol,
  44.     "mtaread",          operation_Qmgr_mtaread,         op_mtaread,
  45.     "mtacontrol",       operation_Qmgr_mtacontrol,      op_mtacontrol,
  46.     "msgcontrol",        operation_Qmgr_msgcontrol,        op_messagecontrol,
  47.     "qmgrcontrol",        operation_Qmgr_qmgrControl,        op_qmgrcontrol,
  48.     "readchannelmtamessage",
  49.                 operation_Qmgr_readChannelMtaMessage,
  50.                         op_readchannelmtamessage,
  51.     "qmgrstatus",        operation_Qmgr_qmgrStatus,        op_qmgrstatus,
  52.     NULL
  53.     };
  54.  
  55. extern int    chan_lose ();
  56. extern int    start_routine ();
  57. extern char *qmgr_hostname;
  58.  
  59. time_t    current_time;
  60. time_t    debris_time = TRASH_RETRY_INTERVAL, load_time = LOAD_RETRY_INTERVAL;
  61. time_t    cache_time = CACHE_TIME, timeout_time = TIMEOUT_RETRY_INTERVAL;
  62. int    chan_state = 1;
  63. int    maxchansrunning = MAXCHANSRUNNING;
  64. int    submission_disabled = 0;
  65. int    nobackground = 0;
  66. int    opmode = 0;
  67. int     nocdir = 0;
  68. int    nodisablemsgclean = 0;
  69.  
  70. /*     MAIN */
  71.  
  72. main (argc, argv)
  73. int     argc;
  74. char  **argv;
  75. {
  76.     int    opt;
  77.     extern char *optarg;
  78.     extern char *pptailor;
  79.  
  80.     myname = argv[0];
  81.     (void) time (¤t_time);
  82.     while ((opt = getopt (argc, argv, "bDd:l:c:Ct:m:MsT:X")) != EOF) {
  83.         switch (opt) {
  84.             case 'b':
  85.             nobackground = 1;
  86.             break;
  87.             case 'C':
  88.             nocdir = 1;
  89.             break;
  90.             case 'D':
  91.             chan_state = 0;
  92.             break;
  93.  
  94.             case 's':
  95.             submission_disabled = 1;
  96.             break;
  97.  
  98.             case 'l':
  99.             if ((load_time = atoi(optarg)) < 0)
  100.                 load_time = LOAD_RETRY_INTERVAL;
  101.             else    load_time *= 60 * 60;
  102.             break;
  103.  
  104.             case 'd':
  105.             if ((debris_time = atoi(optarg)) < 0)
  106.                 debris_time = TRASH_RETRY_INTERVAL;
  107.             else    debris_time *= 60 * 60;
  108.             break;
  109.  
  110.             case 'c':
  111.             if ((cache_time = atoi (optarg)) < 0)
  112.                 cache_time = CACHE_TIME;
  113.             break;
  114.  
  115.             case 't':
  116.             if ((timeout_time = atoi (optarg)) < 0)
  117.                 timeout_time = TIMEOUT_RETRY_INTERVAL;
  118.             else    timeout_time *= 60 * 60;
  119.             break;
  120.  
  121.             case 'm':
  122.             if ((maxchansrunning = atoi (optarg)) < 1)
  123.                 maxchansrunning = MAXCHANSRUNNING;
  124.             break;
  125.  
  126.             case 'M':
  127.             nodisablemsgclean = 1;
  128.             break;
  129.  
  130.             case 'T':
  131.             pptailor = optarg;
  132.             break;
  133.  
  134.             case 'X':
  135.             debug_on ();
  136.             break;
  137.             default:
  138.             adios (NULLCP,
  139. "Usage: %s [-bCDNMsX] [-d hours] [-l hours] [-t hours]\n\t\
  140. [-c secs] [-m nchans] [-T tailorfile]",
  141.                    myname);
  142.             break;
  143.         }
  144.     }
  145.     sys_init (myname);
  146.     srandom(getpid());
  147.  
  148. #if defined(SIGUSR1) && defined(SIGUSR2)
  149.     (void) signal (SIGUSR1, debug_on);
  150.     (void) signal (SIGUSR2, debug_off);
  151. #endif
  152.     (void) signal (SIGTERM, shutdown);
  153.     (void) signal (SIGPIPE, spurious);
  154.     (void) signal (SIGALRM, spurious);
  155.  
  156.     if (nocdir == 0 && chdir (quedfldir) == NOTOK)
  157.         PP_LOG (LLOG_EXCEPTIONS, ("can't cd to %s", quedfldir));
  158.         
  159.     (void) ryresponder (argc, argv,  qmgr_hostname, myservice, dispatches,
  160.                 table_Qmgr_Operations, start_routine,  chan_lose);
  161.  
  162.     exit (0);                       /* NOTREACHED */
  163. }
  164.  
  165. /*     OPERATIONS */
  166.  
  167. static int  op_newmessage (sd, ryo, rox, in, roi)
  168. int     sd;
  169. struct RyOperation *ryo;
  170. struct RoSAPinvoke *rox;
  171. caddr_t in;
  172. struct RoSAPindication *roi;
  173. {
  174.     register struct type_Qmgr_MsgStruct *arg =
  175.         (struct type_Qmgr_MsgStruct *) in;
  176.  
  177.     if (rox -> rox_nolinked == 0) {
  178.         PP_LOG (LLOG_EXCEPTIONS,
  179.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  180.              sd, ryo -> ryo_name, rox -> rox_linkid));
  181.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  182.     }
  183.     PP_TRACE(("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  184.  
  185.     return add_msg (sd, arg, rox, roi);
  186. }
  187.  
  188. static int op_readmsginfo (sd, ryo, rox, in, roi)
  189. int     sd;
  190. struct RyOperation *ryo;
  191. struct RoSAPinvoke *rox;
  192. caddr_t in;
  193. struct RoSAPindication *roi;
  194. {
  195.     register struct type_Qmgr_ReadMessageArgument *arg =
  196.         (struct type_Qmgr_ReadMessageArgument *) in;
  197.  
  198.     if (rox -> rox_nolinked == 0) {
  199.         PP_LOG (LLOG_EXCEPTIONS,
  200.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  201.              sd, ryo -> ryo_name, rox -> rox_linkid));
  202.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  203.     }
  204.  
  205.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  206.  
  207.     return read_msg (sd, arg, rox, roi);
  208. }
  209.  
  210. static int op_channelbegin (sd, ryo, rox, in, roi)
  211. int     sd;
  212. struct RyOperation *ryo;
  213. struct RoSAPinvoke *rox;
  214. caddr_t in;
  215. struct RoSAPindication *roi;
  216. {
  217.     struct type_Qmgr_FilterList *arg = (struct type_Qmgr_FilterList *) in;
  218.  
  219.     if (rox -> rox_nolinked == 0) {
  220.         PP_LOG (LLOG_EXCEPTIONS,
  221.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  222.              sd, ryo -> ryo_name, rox -> rox_linkid));
  223.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  224.     }
  225.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  226.  
  227.     return chan_begin (sd, arg, rox, roi);
  228. }
  229.  
  230. /* ARGSUSED */
  231. static int op_channelread (sd, ryo, rox, in, roi)
  232. int     sd;
  233. struct RyOperation *ryo;
  234. struct RoSAPinvoke *rox;
  235. caddr_t in;
  236. struct RoSAPindication *roi;
  237. {
  238.     struct type_UNIV_UTCTime *arg = (struct type_UNIV_UTCTime *) in;
  239.  
  240.     if (rox -> rox_nolinked == 0) {
  241.         PP_LOG (LLOG_EXCEPTIONS,
  242.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  243.              sd, ryo -> ryo_name, rox -> rox_linkid));
  244.  
  245.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  246.     }
  247.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  248.  
  249.     return channel_list (sd, arg, rox, roi);
  250. }
  251.  
  252. static int op_mtacontrol (sd, ryo, rox, in, roi)
  253. int     sd;
  254. struct RyOperation *ryo;
  255. struct RoSAPinvoke *rox;
  256. caddr_t in;
  257. struct RoSAPindication *roi;
  258. {
  259.     struct type_Qmgr_MtaControl *arg =
  260.         (struct type_Qmgr_MtaControl *) in;
  261.  
  262.     if (rox -> rox_nolinked == 0) {
  263.         PP_LOG (LLOG_EXCEPTIONS,
  264.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  265.              sd, ryo -> ryo_name, rox -> rox_linkid));
  266.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  267.     }
  268.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  269.  
  270.     return mta_control (sd, arg, rox, roi);
  271. }
  272.  
  273. static int op_channelcontrol (sd, ryo, rox, in, roi)
  274. int     sd;
  275. struct RyOperation *ryo;
  276. struct RoSAPinvoke *rox;
  277. caddr_t in;
  278. struct RoSAPindication *roi;
  279. {
  280.     struct type_Qmgr_ChannelControl *arg =
  281.         (struct type_Qmgr_ChannelControl *) in;
  282.  
  283.     if (rox -> rox_nolinked == 0) {
  284.         PP_LOG (LLOG_EXCEPTIONS,
  285.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  286.              sd, ryo -> ryo_name, rox -> rox_linkid));
  287.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  288.     }
  289.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  290.  
  291.     return chan_control (sd, arg, rox, roi);
  292. }
  293.  
  294. static int op_mtaread (sd, ryo, rox, in, roi)
  295. int     sd;
  296. struct RyOperation *ryo;
  297. struct RoSAPinvoke *rox;
  298. caddr_t in;
  299. struct RoSAPindication *roi;
  300. {
  301.     struct type_Qmgr_MtaRead *arg = (struct type_Qmgr_MtaRead *) in;
  302.  
  303.     if (rox -> rox_nolinked == 0) {
  304.         PP_LOG (LLOG_EXCEPTIONS,
  305.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  306.              sd, ryo -> ryo_name, rox -> rox_linkid));
  307.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  308.     }
  309.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  310.  
  311.     return mta_read (sd, arg, rox, roi);
  312. }
  313.  
  314. static int op_messagecontrol (sd, ryo, rox, in, roi)
  315. int    sd;
  316. struct RyOperation *ryo;
  317. struct RoSAPinvoke *rox;
  318. caddr_t in;
  319. struct RoSAPindication *roi;
  320. {
  321.     struct type_Qmgr_MsgControl *arg = (struct type_Qmgr_MsgControl *)in;
  322.  
  323.     if (rox -> rox_nolinked == 0) {
  324.         PP_LOG (LLOG_EXCEPTIONS,
  325.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  326.              sd, ryo -> ryo_name, rox -> rox_linkid));
  327.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  328.     }
  329.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  330.  
  331.     return msg_control (sd, arg, rox, roi);
  332.  
  333. }
  334.  
  335. static int op_qmgrcontrol (sd, ryo, rox, in, roi)
  336. int    sd;
  337. struct RyOperation *ryo;
  338. struct RoSAPinvoke *rox;
  339. caddr_t in;
  340. struct RoSAPindication *roi;
  341. {
  342.     struct type_Qmgr_QMGROp *op = (struct type_Qmgr_QMGROp *) in;
  343.  
  344.     if (rox -> rox_nolinked == 0) {
  345.         PP_LOG (LLOG_EXCEPTIONS,
  346.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  347.              sd, ryo -> ryo_name, rox -> rox_linkid));
  348.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  349.     }
  350.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  351.  
  352.     return qmgrcontrol (sd, (int)op -> parm, rox, roi);
  353. }
  354.  
  355. static int op_readchannelmtamessage (sd, ryo, rox, in, roi)
  356. int    sd;
  357. struct RyOperation *ryo;
  358. struct RoSAPinvoke *rox;
  359. caddr_t in;
  360. struct RoSAPindication *roi;
  361. {
  362.     struct type_Qmgr_MsgRead *mr = (struct type_Qmgr_MsgRead *) in;
  363.  
  364.     if (rox -> rox_nolinked == 0) {
  365.         PP_LOG (LLOG_EXCEPTIONS,
  366.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  367.              sd, ryo -> ryo_name, rox -> rox_linkid));
  368.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  369.     }
  370.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  371.  
  372.     return msgread (sd, mr, rox, roi);
  373. }
  374.  
  375. /* ARGSUSED */
  376. static int op_qmgrstatus (sd, ryo, rox, in, roi)
  377. int    sd;
  378. struct RyOperation *ryo;
  379. struct RoSAPinvoke *rox;
  380. caddr_t in;
  381. struct RoSAPindication *roi;
  382. {
  383.     if (rox -> rox_nolinked == 0) {
  384.         PP_LOG (LLOG_EXCEPTIONS,
  385.             ("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
  386.              sd, ryo -> ryo_name, rox -> rox_linkid));
  387.         return ureject (sd, ROS_IP_LINKED, rox, roi);
  388.     }
  389.     PP_NOTICE (("RO-INVOKE.INDICATION/%d: %s", sd, ryo -> ryo_name));
  390.  
  391.     return qmgrstatus (sd, rox, roi);
  392. }
  393.     
  394.  
  395. /*    ERROR */
  396.  
  397. int  error (sd, err, param, rox, roi)
  398. int     sd,
  399.     err;
  400. caddr_t param;
  401. struct RoSAPinvoke *rox;
  402. struct RoSAPindication *roi;
  403. {
  404.     if (RyDsError (sd, rox -> rox_id, err, param, ROS_NOPRIO, roi) == NOTOK)
  405.         ros_adios (&roi -> roi_preject, "ERROR");
  406.  
  407.     return OK;
  408. }
  409.  
  410. int ureject (sd, reason, rox, roi)
  411. int     sd, reason;
  412. struct RoSAPinvoke *rox;
  413. struct RoSAPindication *roi;
  414. {
  415.     if ( RyDsUReject (sd, rox -> rox_id, reason, ROS_NOPRIO, roi) == NOTOK)
  416.         ros_adios (&roi -> roi_preject, "U-REJECT");
  417.     return OK;
  418. }
  419.  
  420. /* debug control */
  421.  
  422. static int    debugging = -1;
  423.  
  424. /* ARGSUSED */
  425. static SFD debug_on (sig)
  426. int sig;
  427. {
  428.     if (debugging == -1)
  429.         debugging = pp_log_norm -> ll_events;
  430.     if ((pp_log_norm -> ll_events & LLOG_NOTICE) == 0)
  431.         pp_log_norm -> ll_events |= LLOG_NOTICE;
  432.     else if ((pp_log_norm -> ll_events & LLOG_TRACE) == 0)
  433.         pp_log_norm -> ll_events |= LLOG_TRACE;
  434.     else
  435.         pp_log_norm -> ll_events |= LLOG_DEBUG;
  436.     ll_close (pp_log_norm);
  437. }
  438.  
  439. /* ARGSUSED */
  440. static SFD debug_off (sig)
  441. int sig;
  442. {
  443.     if (debugging == -1)
  444.         debugging = pp_log_norm -> ll_events;
  445.     if (debugging != -1) {
  446.         if (pp_log_norm -> ll_events != debugging)
  447.             pp_log_norm -> ll_events = debugging;
  448.         else
  449.             pp_log_norm -> ll_events &= ~LLOG_NOTICE;
  450.         ll_close (pp_log_norm);
  451.     }
  452. }
  453.  
  454. /* ARGSUSED */
  455. static SFD shutdown (sig)
  456. int sig;
  457. {
  458.     opmode = OP_SHUTDOWN;
  459. }
  460.  
  461. static SFD spurious (sig)
  462. int sig;
  463. {
  464.     PP_LOG (LLOG_EXCEPTIONS, ("Spurious signal %d", sig));
  465. }
  466.